package net.sx.minemodule.mvp.activities;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.base.MyBaseFragmentActivity;

import net.sx.minemodule.R;
import net.sx.minemodule.databinding.MineActivityMineOrderLogisticsBinding;
import net.sx.minemodule.mvp.bean.OrderLogisticsBean;
import net.sx.minemodule.mvp.item.OrderLogisticsItemBean;
import net.sx.minemodule.mvp.presenters.MineOrderLogisticsPresenter;
import net.sx.minemodule.mvp.views.MineOrderLogisticsView;

import java.util.List;

/**
 * 描述:  订单商品 物流详情 查看
 * author:胡邦茂
 * CreateDate: 2019/7/13 9:16
 */
@Route(path = ARouterPath.PATH_MINE_ORDER_LOGISTICS)
public class MineOrderLogisticsActivity extends MyBaseFragmentActivity<MineActivityMineOrderLogisticsBinding, MineOrderLogisticsPresenter> implements MineOrderLogisticsView {
    public final static String KEY_ORDER_ID = "id";
    private int mOrderId;
    private ProLogAdapter mAdapter;

    //内容特殊所以 new adapter
    private class ProLogAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
        private LayoutInflater inflater;
        private List<OrderLogisticsItemBean> list;
        private static final int TYPE_TOP = 0x0000;
        private static final int TYPE_NORMAL = 0x0001;

        public ProLogAdapter() {
            inflater = LayoutInflater.from(getContext());
        }

        public void setList(List<OrderLogisticsItemBean> list) {
            this.list = list;
            notifyDataSetChanged();
        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new ViewHolder(inflater.inflate(R.layout.mine_view_order_logistices_item, parent, false));
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            ViewHolder vh = (ViewHolder) holder;
            OrderLogisticsItemBean item = list.get(position);
            vh.tvInfo.setTextColor(item.getColor());
            vh.tvTime.setTextColor(item.getColor());

            if (getItemViewType(position) == TYPE_TOP) {
                vh.tvTopLine.setVisibility(View.INVISIBLE);
                vh.tvDot.setBackgroundResource(R.drawable.mine_shape_oval_select);
            } else if (getItemViewType(position) == TYPE_NORMAL) {
                vh.tvTopLine.setVisibility(View.VISIBLE);
                vh.tvDot.setBackgroundResource(R.drawable.mine_shape_oval_un_select);
            }


            vh.tvInfo.setText(item.getInfo());
            vh.tvTime.setText(item.getTime());
        }

        @Override
        public int getItemCount() {
            return list == null ? 0 : list.size();
        }

        @Override
        public int getItemViewType(int position) {
            if (position == 0) {
                return TYPE_TOP;
            }
            return TYPE_NORMAL;
        }

        public class ViewHolder extends RecyclerView.ViewHolder {
            private TextView tvInfo, tvTime;
            private View tvTopLine, tvDot;

            public ViewHolder(View itemView) {
                super(itemView);
                tvInfo = itemView.findViewById(R.id.tv_info);
                tvTime = itemView.findViewById(R.id.tv_time);
                tvTopLine = itemView.findViewById(R.id.tv_top_line);
                tvDot = itemView.findViewById(R.id.tv_dot);
            }


        }
    }

    @Override
    protected int getLayout() {
        return R.layout.mine_activity_mine_order_logistics;
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        mOrderId = getIntent().getIntExtra(KEY_ORDER_ID, -1);
        initView();
        getPresenter().loadData(mOrderId);
    }

    private void initView() {
        mBinding.rvPro.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new ProLogAdapter();
        mBinding.rvPro.setAdapter(mAdapter);

    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTitle("查看物流");
    }

    @Override
    protected MineOrderLogisticsPresenter getPresenter() {
        return new MineOrderLogisticsPresenter(this);
    }


    @SuppressLint("SetTextI18n")
    @Override
    public void onSucceed(OrderLogisticsBean info) {
      // BindingUtil.loadImage(mBinding.ivPic, info.getPic(), null, getContext().getResources().getDrawable(R.drawable.load_error));
      // mBinding.tvStatus.setText(Html.fromHtml("物流状态：<span style='color:#a541c9'>" + info.getStatus() + "<span>"));
      // mBinding.tvOrderNum.setText(info.getCourierName() + "：" + info.getOrderNum());
      // mAdapter.setList(info.getList());
    }
}
